package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.bean.OrderDetail;
import com.itheima.dao.OrderDetailDao;
import com.itheima.service.OrderDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Slf4j
@Transactional
public class OrderDetailServiceImpl implements OrderDetailService {


    @Autowired
    private OrderDetailDao orderDetailDao;

    @Override
    public int insert(OrderDetail orderDetail) {
        int insert = orderDetailDao.insert(orderDetail);
        return insert;

    }

    /**
     * 根据订单 id 查询
     * @param orderId
     * @return
     */
    @Override
    public List<OrderDetail > findByOrderId(Long orderId) {
        LambdaQueryWrapper<OrderDetail> lqw = new LambdaQueryWrapper<>();
        lqw.eq(OrderDetail::getOrderId, orderId);
        return orderDetailDao.selectList(lqw);
    }
}